using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace Netduino4Fun.Framework.ElectronicBrick
{
    public class PushButton
    {
        InterruptPort input;

        static PushButton()
        {
            //Cpu.GlitchFilterTime = new TimeSpan(0, 0, 0, 0, 10);
        }

        public PushButton(Cpu.Pin pin)
        {
            this.input = new InterruptPort(pin, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
            this.input.OnInterrupt += new NativeEventHandler(input_OnInterrupt);
        }

        void input_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            if (Push != null)
                Push(data1, data2, time);
        }

        public event NativeEventHandler Push;

        public bool Pushed
        {
            get { return this.input.Read(); }
        }
    }
}
